package com.leyou.trade.web;

import com.leyou.trade.dto.OrderFormDTO;
import com.leyou.trade.entity.Order;
import com.leyou.trade.service.OrderService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("order")
public class OrderController {

    private final OrderService orderService;
    public OrderController(OrderService orderService){
        this.orderService=orderService;
    }

    //创建订单
 @PostMapping
    public ResponseEntity<Long>createOrder(@RequestBody OrderFormDTO orderFormDTO, HttpServletRequest request){

        return ResponseEntity.status(HttpStatus.CREATED).body( orderService.createOrder(orderFormDTO,request));
    }

    @GetMapping("{id}")
    public ResponseEntity<Order>queryOrder(@PathVariable("id")Long id){
        return ResponseEntity.ok(this.orderService.getById(id));
    }
    /**
     * 根据订单查询微信支付状态
     * @param orderId
     * @return
     */
//    @GetMapping("/status/{id}")
//    public ResponseEntity<Integer>queryStatus(@PathVariable("id") Long orderId){
//
//        return ResponseEntity.ok( this.orderService.getById(orderId).getStatus());
//    }


}
